﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DevelopTool.Common;
using DevelopTool.Forms.BaseForms;
using DevelopTool.Forms.Properties;
using DevelopTool.Model;

namespace DevelopTool.Forms.DocumentForms
{
    /// <summary>
    /// Oracle常用函数
    /// </summary>
    public partial class OracleCommonFunctionForm : BaseUIPage
    {
        /// <summary>
        /// DataGridView列信息集合
        /// </summary>
        private List<DataGridColumn> dataGridColumns = new List<DataGridColumn>()
              {
                { new DataGridColumn("FunctionName"){ColumnText="函数名称",Width=150,ColumnType=ColumnType.DefaultFilter|ColumnType.RowMain}},
                { new DataGridColumn("Description"){ColumnText="描述",Width=0,ColumnType=ColumnType.DefaultFilter}},
                { new DataGridColumn("Example"){ColumnText="示例",Width=-1,ColumnType = ColumnType.DefaultFilter|ColumnType.LongText,ShowFormProperty=new ShowFormProperty(){
                BaseNameColumn="FunctionName",TextType="SQL"
                }}},
              };

        public OracleCommonFunctionForm()
        {
            InitializeComponent();
        }

        private void OracleCommonFunctionsForm_Load(object sender,EventArgs e)
        {
            //将Json转为DataTable 并根据FunctionName列去重
            DataTable dataTable = ZipHelper.GetContent(Resources.OracleCommonFunction_Json).JsonToDataTable().AsEnumerable()
                      .GroupBy(row => new
                      {
                          Column1 = row.Field<string>("FunctionName")
                      })
                      .Select(group => group.First())
                      .CopyToDataTable();

            this.dataDisplayControl.BindData(dataTable,this.dataGridColumns,"FunctionName ASC");
        }

        private void dataDisplayControl_DataGridViewCellClick(Model.CommonModels.DataGridViewEventArgs dataGridViewEventArgs)
        {
            this.dataDisplayControl.ShowCodeEditor(dataGridViewEventArgs.Row,dataGridViewEventArgs.Row.Cells["Example"],dataGridColumns.Find(it => it.ColumnName == "Example"));

            dataGridViewEventArgs.Cancel = true;
        }
    }
}
